package util;

import entity.CardCollection;
import entity.CreditCard;
import factory.CardFactory;

import java.io.*;

public class Storer {
    public static void read(){
        try(BufferedReader br = new BufferedReader(new FileReader("card.txt"))){
            String line ;
            while((line = br.readLine())!=null){
                CardCollection.getInstance().addCard(CardFactory.createCard(line));
            }
        }catch(IOException e){
            System.out.println(e.getMessage());
        }
    }

    public static void write(){
        try(BufferedWriter bw = new BufferedWriter(new FileWriter("card.txt"))){
            for(CreditCard card : CardCollection.getInstance().cards){
                bw.write(card.toString());
            }
        }catch(IOException e){
            System.out.println(e.getMessage());
        }
    }
}
